// pages/index/cartgroy/cartgroy.js
import {
  getCaVenueRentalPage,
  getCaItemRentalPage,
  getCaItemSalePage
} from "../../../api/place.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    option:1,
    goodsLists: [{
      "goodsList": [{
        "id": 0,
        "photoUrl": "http://yanxuan.nosdn.127.net/1f67b1970ee20fd572b7202da0ff705d.png",
        "service": 0,
        "goods_number": 22,
        "detailText": "日式和风懒人沙发",
        "lostPrice": 0.1
      }]
    }, ],

  },
  onTabsChange(e) {
    this.setData({
      currentTab: e.detail.value,
    })
    console.log(e.detail.value)
    if (e.detail.value == 1) {
      this.getCaItemRentalPage(this.data.option);
    }
    if (e.detail.value == 0) {
      this.getCaVenueRentalPage(this.data.option);
    }
    if (e.detail.value == 2) {
      this.getCaItemSalePage(this.data.option);
    }
  },
  jumpPage(e) {

    let id = e.currentTarget.dataset.id;
    id = JSON.stringify(id)
    let data={
      id:id,
      campid:this.data.option
    }
    data = JSON.stringify(data)
    console.log(data)

    wx.navigateTo({
      url: '../goods_detail/goods_detail?data=' + data
    })
  },
  jumpPage1(e) {
    let id = e.currentTarget.dataset.id;
    id = JSON.stringify(id)
    let data={
      id:id,
      campid:this.data.option
    }
    data = JSON.stringify(data)
    console.log(data)
    wx.navigateTo({
      url: '../gooddetail/gooddetail?data=' + data
    })
  },
  jumpPage2(e) {
    let id = e.currentTarget.dataset.id;
    id = JSON.stringify(id)
    let data={
      id:id,
      campid:this.data.option
    }
    data = JSON.stringify(data)
    console.log(data)
    wx.navigateTo({
      url: '../gooddetail1/gooddetail1?data=' + data
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let id = JSON.parse(options.id);
   this.data.option=id;
    // console.log(id);
    this.getCaVenueRentalPage(id)
    // this.getCaItemRentalPage(id)
  },
  getCaVenueRentalPage(id) {
    // console.log(id)
    let data = {
      "pageNum": "1",
      "pageSize": "10",
      "id": null,
      "caCampId": id,
      "freight": null,
      "service": null,
      "title": null,
      "lostPrice": null,
      "detailText": null,
      "photoUrl": null,
      "praiseNum": null,
      "collectionNum": null,
      "status": null,
      "delFlag": null,
      "createBy": null,
      "createTime": null,
      "updateBy": null,
      "updateTime": null,
      "remark": null
    }
    getCaVenueRentalPage(data).then(res => {
      let datalist = res.data.data.records
      // console.log(res.data.data.records);
      let goodsLists = this.data.goodsLists;
      goodsLists[0].goodsList = datalist
      this.setData({
        goodsLists: goodsLists
      })
      // console.log(this.data.goodsLists);
    })
  },
  getCaItemRentalPage(id) {
    let data = {
      "pageNum": "1",
      "pageSize": "10",
      "id": null,
      "caCampId": id,
      "titleText": null,
      "detailText": null,
      "photoUrl": null,
      "price": null,
      "percentage": null,
      "service": null,
      "inventory": null,
      "praiseNum": null,
      "collectionNum": null,
      "status": null,
      "delFlag": null,
      "createBy": null,
      "createTime": null,
      "updateBy": null,
      "updateTime": null,
      "remark": null
    }
    getCaItemRentalPage(data).then(res => {
      let datalist = res.data.data.records
      // console.log(res.data.data.records);
      let goodsLists = this.data.goodsLists;
      goodsLists[0].goodsList = datalist
      this.setData({
        goodsLists: goodsLists
      })
      console.log(this.data.goodsLists);
    })
  },
  getCaItemSalePage(id) {
    let data = {
      "pageNum": "1",
      "pageSize": "10",
      "id": null,
      "caCampId": id,
      "titleText": null,
      "photoUrl": null,
      "price": null,
      "freight": null,
      "service": null,
      "inventory": null,
      "praiseNum": null,
      "collectionNum": null,
      "status": null,
      "delFlag": null,
      "createBy": null,
      "createTime": null,
      "updateBy": null,
      "updateTime": null,
      "remark": null
    }
    getCaItemSalePage(data).then(res => {
      let datalist = res.data.data.records
      // console.log(res.data.data.records);
      let goodsLists = this.data.goodsLists;
      goodsLists[0].goodsList = datalist
      this.setData({
        goodsLists: goodsLists
      })
      console.log(this.data.goodsLists);
    })
  },
})